package com.abso.mp3tunes.locker.core.data;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.dom4j.Element;

/**
 * The playlist data is returned as a result of an operation involving a
 * playlist.
 */
public class PlaylistData extends AbstractLockerData {

	/** The status code. */
	private int status;

	/** The number of deleted playlists. */
	private int playlistsDeleted;

	/** The updated playlist. */
	private String playlistId;

	/** The number of tracks added. */
	private int tracksAdded;

	/**
	 * Constructs a new playlist data.
	 * 
	 * @param responseElem
	 *            the &lt;mp3tunes&gt; XML element.
	 */
	public PlaylistData(Element responseElem) {
		this.status = LockerDataUtils.getInt(responseElem, "status", -1);
		this.playlistId = LockerDataUtils.getString(responseElem, "playlistId");
		this.tracksAdded = LockerDataUtils.getInt(responseElem, "tracksAdded",
				0);
		this.playlistsDeleted = LockerDataUtils.getInt(responseElem,
				"playlistsDeleted", 0);
	}

	/**
	 * Returns the status: 1 on success, or 0 on failure.
	 * 
	 * @return the status.
	 */
	public int getStatus() {
		return status;
	}

	/**
	 * Returns the identifier of the updated playlist.
	 * 
	 * @return the identifier of the updated playlist.
	 */
	public String getPlaylistId() {
		return playlistId;
	}

	/**
	 * Returns the number of added tracks (if applicable).
	 * 
	 * @return the number of added tracks.
	 */
	public int getTracksAdded() {
		return tracksAdded;
	}

	/**
	 * Returns the number of deleted playlists (if applicable).
	 * 
	 * @return the number of deleted playlists.
	 */
	public int getPlaylistsDeleted() {
		return playlistsDeleted;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}

}
